package tesis.service.impl;

import tesis.service.EnvioEmailService;

import org.apache.velocity.app.VelocityEngine;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;
import javax.inject.Inject;
import org.springframework.beans.factory.annotation.Value;


@Component("envioEmailService")
public class EnvioEmailServiceImpl implements EnvioEmailService {
    @Inject
    private JavaMailSender mailSender;
    @Inject
    private VelocityEngine velocityEngine;
    @Value("#{appProperties.mail_from}")
    private String fromMail;
    @Value("#{appProperties.mail_recover_subject}")
    private String mailRecoverSubject;

    public void envioEmail(String email, String autoGeneratedPassword) {
//        UsuarioDTO usuario = new UsuarioDTO();
//        usuario.setCorreoElectronico(email);
//        usuario.setContrasenhaCorreoElectr("password1");
//        BaseRemoteOutBean baseRemoteOutBean = sendEmail(usuario, autoGeneratedPassword);
//        return baseRemoteOutBean;
    }

//    private BaseRemoteOutBean sendEmail(final UsuarioDTO usuario, final String autoGeneratedPassword) {
//
//        BaseRemoteOutBean baseRemoteOutBean = new BaseRemoteOutBean();
//        baseRemoteOutBean.setError(false);
//        baseRemoteOutBean.setMensaje("Mensaje: sin error");
//
//        MimeMessagePreparator preparator = new MimeMessagePreparator() {
//         public void prepare(MimeMessage mimeMessage) throws Exception {
//            MimeMessageHelper message = new MimeMessageHelper(mimeMessage);
//            message.setTo(usuario.getCorreoElectronico());
//            message.setSubject(mailRecoverSubject);
//            message.setFrom(fromMail);
//            Map model = new HashMap();
//            model.put("password", autoGeneratedPassword);
//            String text = VelocityEngineUtils.mergeTemplateIntoString(
//               velocityEngine, "mail/password.text.vm", model);
//            message.setText(text, true);
//         }
//        };
//        this.mailSender.send(preparator);
//        System.out.println("Se ha enviado el correo");
//
//        return baseRemoteOutBean;
//    }

}
